package cn.thh.basic.service.impl;


import cn.thh.basic.mapper.BaseMapper;
import cn.thh.basic.query.BaseQuery;
import cn.thh.basic.service.IBaseService;
import cn.thh.basic.util.PageList;
import cn.thh.org.domain.Department;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * BaseService不需要交给spring容器管理
 * 直接交给子类继承
 */
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseService<T> implements IBaseService<T> {
    @Autowired
    BaseMapper<T> mapper;


    @Override
    @Transactional
    public void add(T t) {
        mapper.save(t);
    }

    @Override
    public void update(T t) {
        mapper.update(t);
    }

    @Override
    public void del(Long id) {
        mapper.remove(id);
    }

    @Override
    public T getById(Long id) {
        return mapper.loadById(id);
    }

    @Override
    public List<T> getAll() {
        return mapper.loadAll();
    }

    @Override
    public PageList<T> queryPage(BaseQuery baseQuery) {
        //查询出总数
        Integer total = mapper.queryCount(baseQuery);
        //查询出分页数据
        List<T> rows = mapper.queryData(baseQuery);
        return new PageList<T>(total,rows);
    }

    @Override
    public void patchRemove(List<Long> ids) {
        mapper.patchDel(ids);
    }
}
